package net.yunxinyong.cec.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.yunxinyong.cec.entity.Cec711TwoEntity;
import net.yunxinyong.cec.entity.Cec711TwoEntityExample;
import net.yunxinyong.cec.mapper.Cec711TwoMapper;
import net.yunxinyong.cec.service.Cec711TwoService;
import net.yunxinyong.cec.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class Cec711TwoServiceImpl implements Cec711TwoService {
    @Autowired
    private Cec711TwoMapper cec711TISM;

    @Override
    public PageBean<Cec711TwoEntity> findAll(int page,int rows,Cec711TwoEntity cecTwo) {
        Cec711TwoEntityExample cec711TwoEntityExample = new Cec711TwoEntityExample();
        Cec711TwoEntityExample.Criteria criteria = cec711TwoEntityExample.createCriteria();
        if(cecTwo.getId()!=null){
            criteria.andIdEqualTo(cecTwo.getId());
        }
        if (page != 0 && rows != 0) {
            PageHelper.startPage(page, rows);
        }
        List<Cec711TwoEntity> list = cec711TISM.selectByExample(cec711TwoEntityExample);
        //设置分页信息
        PageBean<Cec711TwoEntity> pageBean = new PageBean<>();
        PageInfo<Cec711TwoEntity> pageInfo = new PageInfo<>(list);
        pageBean.setTotal(pageInfo.getTotal());
        pageBean.setTotalPages(pageInfo.getPages());
        pageBean.setPageDatas(list);
        return pageBean;
    }

    @Override
    public int updateById(int id, int status) {
        Cec711TwoEntity cec711TwoInvestmentSituation = new Cec711TwoEntity();
        cec711TwoInvestmentSituation.setId(id);
        cec711TwoInvestmentSituation.setStatus(status);
        cec711TwoInvestmentSituation.setUpdateTime(new Date());
        int count = cec711TISM.updateByPrimaryKeySelective(cec711TwoInvestmentSituation);
        return count;
    }

    @Override
    public int deleteById(int id) {
        Cec711TwoEntity cec711TwoInvestmentSituation = new Cec711TwoEntity();
        cec711TwoInvestmentSituation.setId(id);
        //删除企业信息，把status字段的值改为1:值为1:删除，值为2:正常
        cec711TwoInvestmentSituation.setStatus(1);
        int count = cec711TISM.updateByPrimaryKeySelective(cec711TwoInvestmentSituation);
        return count;
    }

    @Override
    public List<Cec711TwoEntity> findTwoByBaseId(int baseid) {
        Cec711TwoEntityExample cTISE = new Cec711TwoEntityExample();
        Cec711TwoEntityExample.Criteria criteria = cTISE.createCriteria();
        criteria.andBaseIdEqualTo(baseid);
        List<Cec711TwoEntity> list = cec711TISM.selectByExample(cTISE);
        return list;
    }

    //添加企业信息
    @Override
    public int insertTwo(int baseid) {
        Cec711TwoEntity cec711TwoInvestmentSituation = new Cec711TwoEntity();
        cec711TwoInvestmentSituation.setBaseId(baseid);
        //更改表时间
        cec711TwoInvestmentSituation.setUpdateTime(new Date());
        //创建表时间
        cec711TwoInvestmentSituation.setCreateTime(new Date());
        int count = cec711TISM.insertSelective(cec711TwoInvestmentSituation);
        return count;
    }


}
